package com.tdkj.action.backstage.decorate;

import javax.annotation.Resource;

import org.hibernate.Query;

import com.tdkj.action.BaseAction;
import com.tdkj.model.decorate.BeanDiamondCustom;
import com.tdkj.service.decorate.IBeanDiamondCustomService;

public class DiamondCustomAction extends BaseAction {
    
	private IBeanDiamondCustomService diamondCustomService;
	
	private BeanDiamondCustom bean ;
	
	private Long diamondId;
	
	public String execute() {
		
		String hql = "select bean from " + BeanDiamondCustom.class.getName() + " as bean where bean.diamond.id='"+diamondId+"' order by bean.id";
		Query query = this.createQuery(hql);
		this.queryByPage(query, "diamondCustomAction.action", 10);
		
		return "success";
	}
	
	public String add() {
		diamondCustomService.save(bean);
		return execute();
	}
	
	public String update() {
		diamondCustomService.saveOrUpdate(bean, BeanDiamondCustom.class);
		return execute();
	}

	public String delete() {
		diamondCustomService.delete(bean.getId(), BeanDiamondCustom.class);
		return execute();
	}
	
	public String edit() {
		bean = diamondCustomService.findById(bean.getId(), BeanDiamondCustom.class);
		return "edit";
	}

	public BeanDiamondCustom getBean() {
		return bean;
	}

	public void setBean(BeanDiamondCustom bean) {
		this.bean = bean;
	}

	public Long getDiamondId() {
		return diamondId;
	}

	public void setDiamondId(Long diamondId) {
		this.diamondId = diamondId;
	}

	@Resource
	public void setDiamondCustomService(
			IBeanDiamondCustomService diamondCustomService) {
		this.diamondCustomService = diamondCustomService;
	}



	
}
